package com.jianbing.zuixia.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jianbing.common.annotation.Log;
import com.jianbing.common.core.controller.BaseController;
import com.jianbing.common.core.domain.AjaxResult;
import com.jianbing.common.enums.BusinessType;
import com.jianbing.zuixia.domain.ZuixiaUserRelationship;
import com.jianbing.zuixia.service.IZuixiaUserRelationshipService;
import com.jianbing.common.utils.poi.ExcelUtil;
import com.jianbing.common.core.page.TableDataInfo;

/**
 * 用户关联，存储用户基本信息和康复情况Controller
 * 
 * @author windbless
 * @date 2024-07-09
 */
@RestController
@RequestMapping("/zuixia/relationship")
public class ZuixiaUserRelationshipController extends BaseController
{
    @Autowired
    private IZuixiaUserRelationshipService zuixiaUserRelationshipService;

    /**
     * 查询用户关联，存储用户基本信息和康复情况列表
     */
//    @PreAuthorize("@ss.hasPermi('zuixia:relationship:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZuixiaUserRelationship zuixiaUserRelationship)
    {
        startPage();
        List<ZuixiaUserRelationship> list = zuixiaUserRelationshipService.selectZuixiaUserRelationshipList(zuixiaUserRelationship);
        return getDataTable(list);
    }

    /**
     * 导出用户关联，存储用户基本信息和康复情况列表
     */
//    @PreAuthorize("@ss.hasPermi('zuixia:relationship:export')")
//    @Log(title = "用户关联，存储用户基本信息和康复情况", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZuixiaUserRelationship zuixiaUserRelationship)
    {
        List<ZuixiaUserRelationship> list = zuixiaUserRelationshipService.selectZuixiaUserRelationshipList(zuixiaUserRelationship);
        ExcelUtil<ZuixiaUserRelationship> util = new ExcelUtil<ZuixiaUserRelationship>(ZuixiaUserRelationship.class);
        util.exportExcel(response, list, "用户关联，存储用户基本信息和康复情况数据");
    }

    /**
     * 获取用户关联，存储用户基本信息和康复情况详细信息
     */
//    @PreAuthorize("@ss.hasPermi('zuixia:relationship:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return success(zuixiaUserRelationshipService.selectZuixiaUserRelationshipByUserId(userId));
    }

    /**
     * 新增用户关联，存储用户基本信息和康复情况
     */
//    @PreAuthorize("@ss.hasPermi('zuixia:relationship:add')")
//    @Log(title = "用户关联，存储用户基本信息和康复情况", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZuixiaUserRelationship zuixiaUserRelationship)
    {
        return toAjax(zuixiaUserRelationshipService.insertZuixiaUserRelationship(zuixiaUserRelationship));
    }

    /**
     * 修改用户关联，存储用户基本信息和康复情况
     */
//    @PreAuthorize("@ss.hasPermi('zuixia:relationship:edit')")
//    @Log(title = "用户关联，存储用户基本信息和康复情况", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZuixiaUserRelationship zuixiaUserRelationship)
    {
        return toAjax(zuixiaUserRelationshipService.updateZuixiaUserRelationship(zuixiaUserRelationship));
    }

    /**
     * 删除用户关联，存储用户基本信息和康复情况
     */
//    @PreAuthorize("@ss.hasPermi('zuixia:relationship:remove')")
//    @Log(title = "用户关联，存储用户基本信息和康复情况", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(zuixiaUserRelationshipService.deleteZuixiaUserRelationshipByUserIds(userIds));
    }
}
